package com.dylan.历史.领扣;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : ankang
 * @date : 2019/10/11 21:39
 * @Description :
 */
public class $0022括号生成 {
    public static void main(String[] args) {
        System.out.println(new Solution().generateParenthesis(0).size());
    }

    static class Solution {
        public List<String> generateParenthesis(int n) {
            List<String> list = new ArrayList<>();
            func(list, "", 0, 0, n);
            return list;
        }

        public void func(List<String> list, String parenthesis,  int l, int r, int n) {
            if (l > n || r > n || r > l) {
                return;
            }
            if (l == n && r == n) {
                list.add(parenthesis);
                return;
            }
            func(list, parenthesis + "(", l + 1, r, n);
            func(list, parenthesis + ")", l, r + 1, n);
        }
    }
}
